//
//  SupplyPurchasingCell.m
//  有材网
//
//  Created by 肖扬 on 16/1/18.
//  Copyright © 2016年 肖扬. All rights reserved.
//

#import "SupplyPurchasingCell.h"
#import "GoodsModel.h"
@implementation SupplyPurchasingCell
@synthesize bgView,titleLab,textureLab,eplevelLab,priceLab,futureLab,button;
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setBackgroundColor:[UIColor clearColor]];
        self.bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, SWIDTH, 92)];
        self.bgView.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.bgView];
        
        self.titleLab = [self createLabFrame:CGRectMake(10, 8, SWIDTH - 20, 12) text:@"" textColor:BLACKColor tag:10];
        self.titleLab.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:self.titleLab];
        
        self.textureLab = [self createLabFrame:CGRectMake(10, 35, SWIDTH - 20, 13) text:@"" textColor:GRAYColor tag:11];
        self.textureLab.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:self.textureLab];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(10, 55, SWIDTH - 20, 1)];
        line.backgroundColor = GRAYColor;
        line.alpha = 0.3;
        [bgView addSubview:line];
        
        self.eplevelLab = [self createLabFrame:CGRectMake((SWIDTH/2), 35, (SWIDTH/2)-10, 13) text:@"" textColor:GRAYColor tag:12];
        self.eplevelLab.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:self.eplevelLab];
        
        self.priceLab = [self createLabFrame:CGRectMake(10, 68, 0, 0) text:@"" textColor:REDColor tag:13];
        self.priceLab.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:self.priceLab];
        
        self.futureLab = [self createLabFrame:CGRectMake(0, 65, 36, 18) text:@"" textColor:[UIColor whiteColor] tag:14];
        self.futureLab.font = [UIFont systemFontOfSize:12];
        self.futureLab.backgroundColor = UIColorFromRGB(0x2578c3);
        self.futureLab.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:self.futureLab];
        
        self.button = [UIButton buttonWithType:0];
        self.button.frame = CGRectMake(SWIDTH - 90, 94-33, 80, 28);
        [button setBackgroundColor:UIColorFromRGB(0xf84201)];
        [button setTitleColor:[UIColor whiteColor] forState:0];
        [button setTitle:@"我要供货" forState:0];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:self.button];
        
    }
    return self;
}
-(void)drawCell:(id)obj{
    homeModelSupply *goodModel = (homeModelSupply *)obj;
    if (![Unity isBlankString:goodModel.title]) {
        self.titleLab.text = goodModel.title;
    }else{
        NSString *title = @"";
        if (![Unity isBlankString:goodModel.brand_name]) {
            title = [title stringByAppendingString:[NSString stringWithFormat:@"%@",goodModel.brand_name]];
        }
        if (![Unity isBlankString:goodModel.material_name]) {
            title = [title stringByAppendingString:[NSString stringWithFormat:@" %@",goodModel.material_name]];
        }
        self.titleLab.text = title;
    }
    NSString *texture = @"";
    if (![Unity isBlankString:goodModel.texture]) {
        texture = [NSString stringWithFormat:@"花色:%@",goodModel.texture];
    }else{
        texture = [NSString stringWithFormat:@"花色: "];
    }
    NSString *eplevel = @"";
    if (![Unity isBlankString:goodModel.eplevel]) {
        eplevel = [NSString stringWithFormat:@"等级:%@",goodModel.eplevel];
    }else{
        eplevel = [NSString stringWithFormat:@"等级: "];
    }
    NSString *address = @"";
    if (![Unity isBlankString:goodModel.province_name]) {
        address = [NSString stringWithFormat:@"%@",goodModel.province_name];
        if (![Unity isBlankString:goodModel.city_name]) {
            address = [NSString stringWithFormat:@"%@%@",goodModel.province_name,goodModel.city_name];
        }
    }
    self.textureLab.text = [NSString stringWithFormat:@"%@  %@  %@",texture,eplevel,address];
    if (![Unity isBlankString:goodModel.price]) {
        NSString *price = [NSString stringWithFormat:@"%@/%@",goodModel.price,goodModel.unit];
        UIFont *font = [UIFont systemFontOfSize:12];
        CGSize titleSize = [price sizeWithFont:font constrainedToSize:CGSizeMake(MAXFLOAT, 12)];
        self.priceLab.frame = CGRectMake(10, 68, titleSize.width, 12);
        self.priceLab.text = price;
    }
    self.futureLab.frame = CGRectMake(self.priceLab.frame.size.width + self.priceLab.frame.origin.x + 5, 65, 36, 18);
    if ([goodModel.future isEqualToString:@"0"]) {
        self.futureLab.backgroundColor = BLUEColor;
        self.futureLab.text = @"现货";
    }else{
        self.futureLab.backgroundColor = GREENColor;
        self.futureLab.text = @"期货";
    }
}
-(UILabel *)createLabFrame:(CGRect)frame
                      text:(NSString *)text
            textColor:(UIColor *)color
                       tag:(int)tag{
    UILabel *lab = [[UILabel alloc]initWithFrame:frame];
    lab.backgroundColor = [UIColor clearColor];
    lab.textColor = color;
    lab.font = [UIFont systemFontOfSize:12];
    lab.text = text;
    lab.tag = tag;
    return lab;
}
@end
